home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / disk / misc / TransADF.lha / Source / write_disk.c < prev    next >
C/C++ Source or Header  |  1997-12-08  |  3KB  |  98 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <clib/exec_protos.h>
  5. #include <clib/dos_protos.h>
  6.  
  7. #include "write_disk.h"
  8. #include "main.h"
  9. #include "td.h"
  10. #include "util.h"
  11. #include "errors.h"
  12.  
  13.  
  14. #define WD_TBTRACKS 1                           /* Tracks in wd_TrackBuf */
  15. #define WD_TBSIZE   (WD_TBTRACKS * TRACK_SIZE)  /* Bytes in wd_TrackBuf  */
  16.  
  17. UBYTE *wd_TrackBuf;    /* Our input buffer - reads from file. */
  18.  
  19.  
  20. /*
  21. ** Writes a file into a disk.
  22. ** Expects all fields of adfPkt to be set.
  23. */
  24. void writeDisk (struct ADF_Packet *adfPkt)
  25. {
  26.   BYTE TDError;
  27.   LONG DOSError, RWSize;
  28.   int i;
  29.   
  30.   
  31.   /* Output info header */
  32.   FPrintf (StdErr, "Writing from %s to TrackDisk Unit %ld (DF%ld:).\n", 
  33.                    adfPkt->ADFileName,
  34.                    adfPkt->diskUnit,
  35.                    adfPkt->diskUnit);
  36.   
  37.   FPrintf (StdErr, "Starting at track %ld, Ending at track %ld.\n",
  38.                    (adfPkt->startTrack>>1),
  39.                    (adfPkt->endTrack>>1));
  40.   
  41.   /* Allocate track buffer */
  42.   wd_TrackBuf = (UBYTE *) AllocVec (WD_TBSIZE, MEMF_CLEAR);
  43.   if (!wd_TrackBuf)
  44.   {
  45.     /* Out of memory! */
  46.     FPrintf (StdErr, "%s: Out of memory.\n", ProgName);
  47.     cleanExit (RETURN_FAIL, ERROR_NO_FREE_STORE);
  48.   }
  49.   
  50.   /* Start writing */
  51.   for (i = adfPkt->startTrack; i <= adfPkt->endTrack; i++)
  52.   {
  53.     /* Check for Control-C break */
  54.     if (CTRL_C)
  55.     {
  56.       FPutC (StdOut, '\n');
  57.       FPrintf (StdErr, "%s - %s\n", breakText, ProgName);
  58.       cleanExit (RETURN_WARN, NULL);
  59.     }
  60.     
  61.     /* Fill the buffer from file */
  62.     RWSize = Read (adfPkt->ADFile, wd_TrackBuf, WD_TBSIZE);
  63.     if (RWSize != WD_TBSIZE)
  64.     {
  65.       DOSError = IoErr();
  66.       
  67.       FPutC (StdOut, '\n');
  68.       FPrintf (StdErr, "%s: Error reading from %s - ", ProgName,
  69.                                                        adfPkt->ADFileName);
  70.       if (DOSError)
  71.         reportDOSError (DOSError);
  72.       else
  73.         FPuts (StdErr, "File to short.\n");
  74.       
  75.       cleanExit (RETURN_ERROR, DOSError);
  76.     }
  77.     
  78.     /* Update progress information */
  79.     FPuts (StdOut, "\rWriting ");
  80.     FPUTS_TS (i, StdOut);
  81.     Flush (StdOut);
  82.     
  83.     /* Write the buffer to the disk */
  84.     TDError = writeTrack (wd_TrackBuf, WD_TBTRACKS, i, adfPkt->diskReq);
  85.     if (TDError)
  86.     {
  87.       FPutC (StdOut, '\n');
  88.       FPrintf (StdErr, "%s: Error writing to DF%ld: - ",ProgName,
  89.                                                         adfPkt->diskUnit);
  90.       reportTDError (TDError);
  91.       cleanExit (RETURN_ERROR, NULL);
  92.     }
  93.   }
  94.   
  95.   /* Free buffer */
  96.   FreeVec (wd_TrackBuf); wd_TrackBuf = NULL;
  97. }
  98.